/**
 * 
 */
package neptune.web.client;

import java.util.ArrayList;

import neptune.web.client.model.SerializableExperiment;
import neptune.web.client.model.SerializableExperimentState;
import neptune.web.client.model.topology.SerializableIPAddress;
import neptune.web.client.model.topology.SerializableNetworkInterface;
import neptune.web.client.model.topology.SerializableNode;
import neptune.web.client.model.topology.SerializableTopology;
import neptune.web.client.view.ClusterView;
import neptune.web.client.view.components.ExperimentAdministrationPanel;
import neptune.web.client.view.components.NodesManager;
import neptune.web.client.view.components.dialogs.HelpDialog;
import neptune.web.client.view.components.editor.TopologyEditor;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Vathalas
 * 
 */
public class InterfaceTEST implements EntryPoint {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
	 */
	public void onModuleLoad() {
		RootPanel.get("preloading").setVisible(false);

		// Widget pan = testTopologyEditor();
		Widget pan = expViewTEST();
		RootPanel.get("wrapper").add(pan);
	}

	private Widget expViewTEST() {
		ExperimentAdministrationPanel pan = new ExperimentAdministrationPanel();

		SerializableExperiment exp = new SerializableExperiment();
		exp.setExperimentId("Esperimento");
		exp.setAdministrator("Roberto");
		SerializableIPAddress addr = new SerializableIPAddress();
		addr.setAddress("10.0.0.0");
		addr.setSubnetMask("255.255.0.0");
		exp.setAssignedSubnet(addr);

		SerializableExperimentState state = new SerializableExperimentState();
		state.setState("DEFINED");
		state.setCreationTimestamp(0);
		state.setStartTimestamp(0);
		state.setStopTimestamp(0);
		state.setTotalExecutionTime(0);
		exp.setState(state);
		pan.setData(exp);
		return pan;
	}

	private Widget deployTEST() {
		// ManualAllocationDialog dialog = new ManualAllocationDialog(
		// new String[] { "node1", "node2", "node3" },
		// new String[] { "pm1", "pm2", "pm3" });
		// dialog.center();
		return new SimplePanel();
	}

	private Widget clusterViewTEST() {
		ClusterView view = new ClusterView();
		view.addPhysicalMachine("1", "pippo","pm1", "192.168.1.18", "80%", "1024/2048",
				"130/200");
		view.addPhysicalMachine("2","pluto","pm2", "192.168.1.18", "80%", "1024/2048",
				"130/200");
		view.addPhysicalMachine("3", "paperino","pm3", "192.168.1.18", "80%", "1024/2048",
				"130/200");
		view.addPhysicalMachine("4","paperone","pm4", "192.168.1.18", "80%", "1024/2048",
				"130/200");
		view.setPMIcon("pm1", ClusterView.NOT_IN_SYNC_ICON);
		view.setPMIcon("pm2", ClusterView.ERROR_ICON);
		view.setPMIcon("pm3", ClusterView.UPDATING_ICON);
		return view;
	}

	private Widget testTopologyEditor() {
		TopologyEditor pan = new TopologyEditor();

		SerializableTopology topo = new SerializableTopology();

		SerializableNode node = new SerializableNode();
		node.setId("node1");

		SerializableNetworkInterface netIf = new SerializableNetworkInterface();
		netIf.setInterfaceName("eth0");
		ArrayList<SerializableNetworkInterface> ifs = new ArrayList<SerializableNetworkInterface>(
				0);
		ifs.add(netIf);

		node.setInterfaces(ifs);

		ArrayList<SerializableNode> nodes = new ArrayList<SerializableNode>(0);
		nodes.add(node);
		nodes.add(node);
		nodes.add(node);

		topo.setNodes(nodes);

		pan.setTopology(topo);
		return pan;
	}

	private Widget helpDialogTEST() {
		HelpDialog dialog = new HelpDialog(GWT.getHostPageBaseURL()
				+ "Operative.admin.help.html");
		dialog.show();
		return new SimplePanel();
	}

	private Widget nodeManagerTEST() {
		NodesManager manager = new NodesManager(400);
		manager.addNode("node1", "RUNNING", "10.0.0.1");
		manager.addNode("node2", "RUNNING", "10.0.0.1");
		manager.addNode("node3", NodesManager.PAUSED_STATE, "10.0.0.1");

		for (int i = 4; i < 20; i++) {
			manager.addNode("node" + i, "RUNNING", "10.0.0.1");
		}

		manager.setNodeInfos("node5", NodesManager.PAUSED_STATE, "10.0.0.3");
		manager.setNodeInfos("node3", NodesManager.RUNNING_STATE, "10.0.0.3");

		manager.setVMIcon("node2", 0);
		return manager;
	}
}
